//
//  ClickButton.m
//  HuaMuJinRong
//
//  Created by Cindy on 15/12/18.
//  Copyright (c) 2015年 EIMS. All rights reserved.
//

#import "ClickButton.h"

@implementation ClickButton

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor clearColor];
        
        self.layer.cornerRadius = 4;
        [self.layer setMasksToBounds:YES];
        
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
        self.titleLabel.font = KFontSize(15.0f);
        
        UIImage *image = [CommonClass imageWithColor:KButtonNormalColor];
        UIImage *highlightedImage = [CommonClass imageWithColor:KButtonSelectColor];
        
        [self setBackgroundImage:image forState:UIControlStateNormal];
        [self setBackgroundImage:highlightedImage forState:UIControlStateHighlighted];
        
    }
    return self;
}

- (void)setButtonEnable:(BOOL)buttonEnable {
    
    if (!buttonEnable) {
        UIImage *image = [CommonClass imageWithColor:[ColorTools colorWithHexString:@"#cccccc"]];
        UIImage *highlightedImage = [CommonClass imageWithColor:[ColorTools colorWithHexString:@"#cccccc"]];
        
        [self setBackgroundImage:image forState:UIControlStateNormal];
        [self setBackgroundImage:highlightedImage forState:UIControlStateHighlighted];
        
        self.enabled = NO;
        
    }else {
        UIImage *image = [CommonClass imageWithColor:KButtonNormalColor];
        UIImage *highlightedImage = [CommonClass imageWithColor:KButtonSelectColor];
        
        [self setBackgroundImage:image forState:UIControlStateNormal];
        [self setBackgroundImage:highlightedImage forState:UIControlStateHighlighted];
        
        self.enabled = YES;
    }
}

- (void)setButtonEnableStaus:(BOOL)enable {
    if (!enable) {
        UIImage *image = [CommonClass imageWithColor:[ColorTools colorWithHexString:@"#cccccc"]];
        UIImage *highlightedImage = [CommonClass imageWithColor:[ColorTools colorWithHexString:@"#cccccc"]];
        
        [self setBackgroundImage:image forState:UIControlStateNormal];
        [self setBackgroundImage:highlightedImage forState:UIControlStateHighlighted];
        
        self.enabled = NO;
        
    }else {
        UIImage *image = [CommonClass imageWithColor:KButtonNormalColor];
        UIImage *highlightedImage = [CommonClass imageWithColor:KButtonSelectColor];
        
        [self setBackgroundImage:image forState:UIControlStateNormal];
        [self setBackgroundImage:highlightedImage forState:UIControlStateHighlighted];
        
        self.enabled = YES;
    }
}

- (void)setBackColor:(UIColor *)color HighlightColor:(UIColor *)highlightColor
{
    UIImage *image = [CommonClass imageWithColor:color];
    [self setBackgroundImage:image forState:UIControlStateNormal];
    
    if (highlightColor != nil) {
        UIImage *highlightedImage = [CommonClass imageWithColor:highlightColor];
        [self setBackgroundImage:highlightedImage forState:UIControlStateHighlighted];
    }
}


@end
